﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLNHDAO;
using QLNHBUS;
using System.Resources;
using PMQLNhaHang.CustomControl;
using System.Globalization;

namespace PMQLNhaHang
{
    public partial class fmQLKho : Form
    {
        public fmQLKho()
        {
            InitializeComponent();
        }

        private void btnThemDM_Click(object sender, EventArgs e)
        {
            fmQLKhoDanhMuc dm = new fmQLKhoDanhMuc();
            dm.ShowDialog();
        }

        private void btnSuaDanhMuc_Click(object sender, EventArgs e)
        {
            fmQLKhoDanhMuc dm = new fmQLKhoDanhMuc();
            dm.ShowDialog();
        }

        private void btnThemSanPham_Click(object sender, EventArgs e)
        {
            fmQLKhoSanPham sp = new fmQLKhoSanPham();
            sp.ShowDialog();
        }

        private void btnXoaDM_Click(object sender, EventArgs e)
        {

        }

        private void fmQLKho_Load(object sender, EventArgs e)
        {
            LoadDSDanhMuc();
        }

        private void LoadDSDanhMuc()
        {
            exlbDMSanPham.Items.Clear();
            List<NhomSanPham> dsNhomSanPham = NhomSanPhamBUS.LayDanhSachNhomSanPhamChuaXoa();
            var rm = new ResourceManager(typeof(exListBox));
            var img = (Image)rm.GetObject("Table_icon");
            foreach (var t in dsNhomSanPham)
            {
                string detail = t.MaNhomSanPham.ToString(CultureInfo.InvariantCulture);
                var ex = new exListBoxItem(t.MaNhomSanPham, t.Ten, detail, img);
                exlbDMSanPham.Items.Add(ex);
            }
        }

        private void exlbDMSanPham_SelectedIndexChanged(object sender, EventArgs e)
        {
            RefreshDSSanPham();
        }

        private void RefreshDSSanPham()
        {
            var sel = (exListBoxItem)exlbDMSanPham.SelectedItem;
            if (sel != null)
            {
                var dssanpham = SanPhamBUS.LayDanhSachSanPhamChuaXoa(sel.Id);
                dgvDSSanPham.DataSource = dssanpham.ToList();
            }
            else
            {
                dgvDSSanPham.DataSource = null;
            }
        }

        private void btnXoaSanPham_Click(object sender, EventArgs e)
        {           
            MessageBox.Show(SanPhamBUS.TestThemSP());
        }
    }
}
